package cn.by.wms.config;

import cn.by.wms.javaweb.LogTimeFilter;
import cn.by.wms.javaweb.MyListener;
import cn.by.wms.javaweb.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JavaWebConfig {

   // @Bean
    public ServletRegistrationBean servletRegistrationBean(){
        ServletRegistrationBean  bean = new ServletRegistrationBean();
        bean.setServlet(new MyServlet());
        bean.addUrlMappings("/servlet");
        return bean;
    }

   // @Bean
    public ServletListenerRegistrationBean servletListenerRegistrationBean(){
        ServletListenerRegistrationBean  bean = new ServletListenerRegistrationBean();
        bean.setListener(new MyListener());
        return bean;
    }

    // @Bean
    public FilterRegistrationBean filterRegistrationBean(){
         FilterRegistrationBean  bean = new FilterRegistrationBean(new LogTimeFilter());
         bean.addUrlPatterns("/api/*");
         bean.setOrder(1);
        return bean;
    }
}
